package com.example.rwq_test.designParttern.multiThread.WorkerThread;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * 发送工作的请求类
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2022/11/5
 */
public class ClientThread extends Thread {
    private final Channel channel;
    private static final Random random = new Random();

    public ClientThread(String name, Channel channel) {
        super(name);
        this.channel = channel;
    }

    public void run() {
        try {
            for (int i = 0; true; i++) {
                Request request = new Request(getName(), i);
                channel.putRequest(request);
                TimeUnit.MILLISECONDS.sleep(random.nextInt(1000));
            }
        } catch (InterruptedException e) {
        }
    }
}
